package com.PortalAsteroidjava;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.*;
import com.badlogic.gdx.files.*;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.*;

import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

public class PortalAsteroidjava implements ApplicationListener {
	private SpriteBatch batch;
	private GameModel model;
	private GameControl controller;

	public static Texture playerTexture;
	public static Texture asteroidTexture;
	public static Texture missileTexture;
	public static Texture wormholeTexture;

	@Override
	public void create() {
		playerTexture = new Texture(Gdx.files.internal("data/spaceship.jpg"));
		asteroidTexture = new Texture(Gdx.files.internal("data/asteroid.png"));
		missileTexture = new Texture(Gdx.files.internal("data/missile.gif"));
		wormholeTexture = new Texture(Gdx.files.internal("data/wormhole.png"));
		
		batch = new SpriteBatch();
		model = new GameModel();
		controller = new GameControl();
		Gdx.input.setInputProcessor(controller);
	}

	@Override
	public void dispose() {
		
	}

	@Override
	public void pause() {
		
	}

	@Override
	public void render() {
		
		if(controller.buttons[0])
			model.movePlayer(0, 1);
		else if (controller.buttons[1])
			model.movePlayer(0, -1);
		else if (controller.buttons[2])
			model.movePlayer(-1, 0);
		else if (controller.buttons[3])
			model.movePlayer(1, 0);
		
		
		Gdx.gl.glClearColor(0,0,0,1);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		batch.begin();
		for(Sprite s : model.getSprites())
			s.draw(batch);
		batch.end();
	}

	@Override
	public void resize(int arg0, int arg1) {
		
	}

	@Override
	public void resume() {
		
	}
	
    public void keyPressed(KeyEvent e)
    {
    	Gdx.app.log("PortalAsteroidjava", "Key Pressed");
    }

}
